package com.yanqu.road.server.cmd.minewar;

import com.yanqu.road.pb.minewar.MineWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.MineWarModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

import java.util.ArrayList;
import java.util.List;

@Cmd(code= Protocol.S_MINE_WAR_REFUGE_DISPATCH, desc = "矿场避难所派遣")
public class MineRefugeDispatchCmd extends AbstractCommand {

    private int mineType;

    private int pitId;

    private List<Integer> patronsIdList;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MineWarProto.MineRefugeDispatchReqMsg reqMsg = MineWarProto.MineRefugeDispatchReqMsg.parseFrom(packet.getBytes());
        mineType = reqMsg.getMineType();
        pitId = reqMsg.getPitId();
        patronsIdList = new ArrayList<>();
        for(int patronsId : reqMsg.getPatronsIdListList()){
            if(!patronsIdList.contains(patronsId)){
                patronsIdList.add(patronsId);
            }
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        player.sendPacket(Protocol.U_MINE_WAR_REFUGE_DISPATCH, player.getModule(MineWarModule.class).refugeDispatch(mineType, pitId, patronsIdList));
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
